/**
 * Created by Administrator on 2018/7/29/029.
 */
layui.use(['form', 'layer'], function () {

    // 操作对象
    var form = layui.form
        , layer = layui.layer
        , $ = layui.jquery;


    var token = $('#_token').val();

    form.on('submit(setting)',function(data){
        var data = data.field;
        var passreg  = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$/;

        if(!passreg.test(data.password)) {
            layer.msg('密码必须为8-20位字母与数字组合密码',{anim:6,icon:5},function(){});
            return false;
        }


        if(data.new_password != data.password){
            layer.msg('两次密码不一致',{anim:6,icon:5},function(){});
            return false;
        }

        resetPassword(data)
    });


    //重置密码
    function resetPassword(data){
        data._token = token;
        data.u_id = u_param.uuid;
        $.ajax({
            url: '/resettingPassword',          //  删除账号
            type: 'post',
            data: data,
            timeout: 5000,
            dataType: 'json',
            success: function (data, textStatus, jqXHR) {
                if (data.error_code == 0) {
                    layer.msg('重置密码成功',{
                        time: 2000,
                        end:function(e){
                            layer.closeAll('page');
                            getMemeberDetail()
                        }});
                } else {
                    layer.msg('重置密码失败',{
                        time: 2000,
                        end:function(e){
                            layer.closeAll('page');
                            getMemeberDetail()
                        }});
                }
            },
            error:function(){
                layer.msg('出错了',{
                    time: 2000,
                    end:function(e){
                        layer.closeAll('page');
                        getMemeberDetail()
                    }});
            }
        });
    }

});